package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.SysUserSyTypeVo;
import com.ruoyi.system.domain.bo.SysUserSyTypeBo;
import com.ruoyi.system.service.ISysUserSyTypeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户试验类型范围
 *
 * @author zyb
 * @date 2024-04-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userSyType")
public class SysUserSyTypeController extends BaseController {

    private final ISysUserSyTypeService iSysUserSyTypeService;

    /**
     * 查询用户试验类型范围列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<SysUserSyTypeVo> list(SysUserSyTypeBo bo, PageQuery pageQuery) {
        return iSysUserSyTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户试验类型范围列表
     */
    @SaCheckLogin
    @Log(title = "用户试验类型范围", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysUserSyTypeBo bo, HttpServletResponse response) {
        List<SysUserSyTypeVo> list = iSysUserSyTypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户试验类型范围", SysUserSyTypeVo.class, response);
    }

    /**
     * 获取用户试验类型范围详细信息
     *
     * @param userId 主键
     */
    @SaCheckLogin
    @GetMapping("/{userId}")
    public R<SysUserSyTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long userId) {
        return R.ok(iSysUserSyTypeService.queryById(userId));
    }

    /**
     * 新增用户试验类型范围
     */
    @SaCheckLogin
    @Log(title = "用户试验类型范围", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysUserSyTypeBo bo) {
        return toAjax(iSysUserSyTypeService.insertByBo(bo));
    }

    /**
     * 修改用户试验类型范围
     */
    @SaCheckLogin
    @Log(title = "用户试验类型范围", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysUserSyTypeBo bo) {
        return toAjax(iSysUserSyTypeService.updateByBo(bo));
    }

    /**
     * 删除用户试验类型范围
     *
     * @param userIds 主键串
     */
    @SaCheckLogin
    @Log(title = "用户试验类型范围", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] userIds) {
        return toAjax(iSysUserSyTypeService.deleteWithValidByIds(Arrays.asList(userIds), true));
    }
}
